package com.lry.basic.nio;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/9/9
 */
public class Demo3 {
    public static void main(String[] args) throws IOException {
        transferFrom();
    }
    public static void transferFrom() throws IOException {
        RandomAccessFile fromFile = new RandomAccessFile("D:\\1.txt", "rw");
        FileChannel fromChannel = fromFile.getChannel();

        RandomAccessFile toFile = new RandomAccessFile("D:\\2.txt", "rw");
        FileChannel toChannel = toFile.getChannel();

        long position = 0;
        long count = fromChannel.size();
        //从fromChannel-->> toChannel
//        toChannel.transferFrom(fromChannel,position,count);
        //从fromChannel-->> toChannel
        fromChannel.transferTo(position,count,toChannel);
    }
}
